package com.simba.server.commands.impl.web;

import com.simba.common.command.ICommand;
import com.simba.server.components.SorterParams;
import com.simba.server.components.data.ResultInfo;
import org.apache.log4j.Logger;

import com.simba.common.log.LogUtil;
import com.simba.server.ServerParam;
import com.simba.server.components.data.SortInfo;
import com.simba.server.webservice.WebServiceManager;

/**
 * 扫描信息回传
 *
 * @return success or error
 */
public class WebPacketScanCmd implements ICommand
{
	public static final String NAME = "WebPacketScanCmd";
	private static final Logger logger = Logger.getLogger(WebPacketScanCmd.class);
	private final SortInfo sort;

	public WebPacketScanCmd(SortInfo sort)
	{
		this.sort = sort;
	}

	@Override
	public String getName()
	{
		return WebPacketScanCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;
		String remoteMethod = "getYJSM";

		String content = "";
		try
		{
			if (SorterParams.getInstance().isDebugMode()){
				LogUtil.LogError(logger, "upload scan into error: debug mode doesn't upload data!");
				return false;
			}

			ResultInfo response = WebServiceManager.getInstance().doNothing(
					ServerParam.REMOTE_WEBSERVICE_ADDRESS, remoteMethod, content);
			if (response != null)
			{
				ret = this.handleResponse(response);
			}
		}
		catch (Exception e)
		{
			LogUtil.LogError(WebPacketScanCmd.logger, "upload scan info error: " + e);
			ret = false;
		}
		return ret;
	}

	private boolean handleResponse(ResultInfo response)
	{
		boolean ret = false;
		try
		{
			ret = true;
		}
		catch (Exception e)
		{
			LogUtil.LogError(WebPacketScanCmd.logger, "parse scan message result failed : " + e);
		}
		return ret;
	}
}
